package com.atguigu.dga.util;

import com.baomidou.mybatisplus.extension.api.R;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

/**
 * ClassName: HttpUtil
 * Package: com.atguigu.dga.util
 * Description:
 *
 * @Author:
 * @Create: 2024/3/22 09:04
 * @Version: 1.0
 */
public class HttpUtil {
    // TODO DS数据倾斜指标：创建okHttpClient 请求spark历史服务器接口
    private static OkHttpClient httpClient = new OkHttpClient();

    public static String get(String url ) throws IOException {
        //创建request对象
        Request.Builder builder = new Request.Builder();
        Request request = builder.url(url)
                .get()
                .build();
        Call call = httpClient.newCall(request);
        Response response = call.execute();
        String result = response.body().string();
        return result;
    }

    // 测试
    public static void main(String[] args) throws IOException {
        String url = "http://localhost:18081/api/v1/applications/application_1684083580862_0012/1/stages/2";
        String s = get(url);
        System.out.println(s);
    }
}
